package com.js.blog.config;

import com.js.blog.interceptor.JWTInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

/**
 * @author yanglin
 * @create 2024-02-29 17:40 星期四
 * description:
 */
@Configuration
public class JWTInterceptorConfig extends WebMvcConfigurationSupport {

    /**
     * 自定义拦截器规则：排除登录接口和注册接口
     */
    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(jwtInterceptor())
                .excludePathPatterns("/admin/login","/admin/register");
        super.addInterceptors(registry);
    }


    @Override
    protected void configurePathMatch(PathMatchConfigurer configurer) {
        configurer.setUseRegisteredSuffixPatternMatch(true);
    }

    /**
     * 把自定义拦截器放入容器中
     */
    @Bean
    public JWTInterceptor jwtInterceptor(){
        
        return new JWTInterceptor();
    }
}
